<?php

namespace App\Http\Controllers\Api;

use App\Models\News;
use App\Transformers\NewsTransformer;
use Illuminate\Http\Request;

class NewsController extends Controller
{
    public function index(Request $request)
    {
        $key = $request->only([
            //??
        ]);

        $data = News::where('is_show', 1)->where($key)->orderBy('created_at', 'desc')->paginate();

        return $this->response->paginator($data, new NewsTransformer([], $this->user));
    }

    public function show($id)
    {
        $data = News::find($id);

        if (!$data) {
            $this->response->error(trans('api.not_exists'), 200);
        }

        //增加浏览量
        $data->increment('view_amount');

        return $this->response->item($data, new NewsTransformer([], $this->user));
    }
}
